<?php
//DB Created by Rich L. a member in service in Northern Delaware.  Please feel free to share this code wherever it may be useful to alcholoics.  Should you have questons please contact me at sobernerd@gmail.com
if ($_SESSION['logged_in'] == 0) {
	require ('../../admin/security_check.php');
} else {
	if ($_POST)
{
	processTable('locations');
}	
/* location query */
$locations_sql = "SELECT meetings.group_id, locations.id as id, locations.name AS name, locations.city AS city, locations.state AS state, count(meetings.group_id) AS counter
	FROM meetings
	RIGHT JOIN locations ON locations.id = meetings.location_id
	GROUP BY meetings.location_id, locations.name
	ORDER BY name ASC";
$locations_result = mysql_query($locations_sql) or die(mysql_error());
$num_rows = mysql_num_rows($locations_result);
?>
<script language="javascript" type="text/javascript">
var table = 'locations';

$(document).ready(function(){ 
	$('.meetingEdit').editable('inlineEdit.php', {
			 indicator : 'Saving...',
			 tooltip   : 'Click to edit...',
			 style     : 'display: inline',
			 submitdata : {table: table},
			 submit    : '<span>&nbsp;&nbsp;<input type="submit" value="OK"></span>',
			 callback : function(value, settings) {
				$(this).next('.message').show();
				$(this).next('.message').html('');
         		$(this).next('.message').append('Updated');
				$(this).next('.message').fadeOut(2000);
    		 }
     });
	 var sum = 0;
	 var thisNum = 0;

	 $('.meetingLocationMtgCount').each(function() {
		thisNum = parseInt($(this).html());
		if(thisNum == 0) {
        	sum += 1;
			$(this).closest('tr').attr('bgcolor','#FF6666');
		}
    });
	$('#wrapper div.main_content table.tabletext thead.meetingHeader tr.titleRow th h3').append('&nbsp;&nbsp; - &nbsp;&nbsp;('+sum+'&nbsp; with no meetings)');
});
</script>

<table class="tabletext tablegroups">
  <thead class="meetingHeader">
    <tr class="titleRow">
      <th colspan="4"><h3>Locations&nbsp;&nbsp;&nbsp;(<?php echo $num_rows ?>)</h3></th>
    </tr>
    <tr class="alternateRow">
      <th>Location</th>
      <th>City</th>
      <th id="numMtgsHeader"># of Meetings</th>
      <th></th>
    </tr>
  </thead>
  <?php		
$i = 0;
while ($locations_row = mysql_fetch_assoc($locations_result))
	{
		if ($i%2 == 0) 
		{
		$rowcolor="$reprowcolor";
		} else 
		{
		$rowcolor="white";
		}	
	
		
		
			//report data	?>
  <tr bgcolor="<?php echo $rowcolor?>">
    <td><div class="meetingLocationName"><span class="meetingEdit" id="<?php echo $locations_row['id'];?>_name"><?php echo $locations_row['name'];?></span><span class="message"></span></div></td>
    <td><div class="meetingLocationCity"><?php echo $locations_row['city'].', '.$locations_row['state'];?></div></td>
    <td><div class="meetingLocationMtgCount"><?php echo $locations_row['counter'];?></div></td>
    <td><div class="meetingDelete"> 
    		<a href="meetings.php?page=location_edit&id=<?php echo $locations_row['id']?>&return_to=meetings.php?page=locations"><img src="../images/edit_button.png"></a>
        	<a href="deleteform.php?id=<?php echo $locations_row['id']?>&table=locations&return_to=meetings.php?page=locations"><img src="../images/delete_button.png"></a>
        </div>
    </td>
  </tr>
  <?php 
	$i++;				
	}
echo "</table>";
mysql_close($conn);}?>
</table>
